<include file="../Public/_top" />
<style type="text/css">
  .sel_box{
    width:240px;
    float:left;
    height:60px;
    line-height:60px;
  }
  .sel{
    border:1px solid #eeeeee;
    width:130px;
    height:40px;
    margin:15px;
  }
</style>
<div class="content">
  <div class="wrap">
      <include file="./_left" />
        <div class="con_main">
          <div class="con_tit">
            <ul class="con_link">
              <li <php>if(ACTION_NAME == 'TestData'){</php> class="on" <php>}</php>><a href="{:U('public/TestData/TestData')}">已测试</a></li>
              <li <php>if(ACTION_NAME == 'addTest'){</php> class="on" <php>}</php>><a href="{:U('public/TestData/addTest')}">新建测试</a></li>
            </ul>
            <div class="search_wrap">
              <input class="search_inp" type="text" id="name" placeholder="按姓名搜索">
              <input class="search_btn" type="submit" value="" onclick="select_filter();">
            </div>
          </div>
            <div style="width:100%;height:140px;padding:15px;">
              <div class="sel_box">
                选择时间：
                <select id="year" class="sel">
                  <option value="">--------请选择--------</option>
                  <volist name="year" id="year">
                    <option value="{$year}">{$year}</option>
                  </volist>
                </select>
              </div>
              <div class="sel_box">
                测试次数：
                <select id="test_number" class="sel">
                  <option value="">--------请选择--------</option>
                  <option value="1">第1次</option>
                  <option value="2">第2次</option>
                  <option value="3">第3次</option>
                  <option value="4">第4次</option>
                  <option value="5">第5次</option>
                  <option value="6">第6次</option>
                  <option value="7">第7次</option>
                  <option value="8">第8次</option>
                  <option value="9">第9次</option>
                  <option value="10">第10次</option>
                </select>
              </div>
              <div class="sel_box">
                选择年级：
                <select id="grade" class="sel" onchange="selectGrade();">
                    <option value="">--------请选择--------</option>
                    <option value="1">大班</option>
                    <option value="2">中班</option>
                    <option value="3">小班</option>
                    <option value="4">混龄班</option>
                </select>
              </div>
              <div class="sel_box">
                选择班级：
                  <select id="Class" class="sel">
                    <option value="">--------请选择--------</option>
                  </select>
              </div>
              <div class="action_link tc" style="margin-top:90px;">
                <a class="dowm" href="javascript:select_filter();">确定</a>
              </div>
            </div>
            <div class="con_tit">
                <table class="table table_title t7_2">
                  <tr>
                    <td>姓名</td>
                    <td>年级</td>
                    <td>班级</td>
                    <td>测试次数</td>
                    <td>测试年份</td>
                    <td>完成度</td>
                    <td>操作</td>
                  </tr>
                </table>
            </div>
            <div class="con_box" id="test_list"></div>
            <div class="action_link tc" id="allreport" style="margin-left: -200px;"></div>
        </div>
    </div>
</div>
<script>
var userGroup="<?php echo $userGroup; ?>";
var classId="<?php echo $classId; ?>";
if(userGroup==5){
  $("#grade").attr("disabled","disabled");  
  $("#Class").attr("disabled","disabled"); 
    $.ajax({
    type: "GET",
    url:"{:U('public/TestData/getList')}",
    data:"is_report=0&p=1&Class="+classId,
    dataType:"json", 
    success:function(data){
        appendHtml(data);
    }
  });
}
 //追加html
function appendHtml(data){
    $("#test_list").html("");
    $("#test_list").append(data.data);
    var html="<div class='pagebox'>";
    if(data.nowPage>1 ){
        page=data.nowPage-1;
        html+="<a href=\"javascript:getList("+page+")\">上一页</a>";
    }
    for (var i = 1; i <=data.totalPages; i++) {
        if(i==data.nowPage){
            html+="<a href=\"javascript:getList("+i+")\" class='on'>"+i+"</a>";
        }else{
            html+="<a href=\"javascript:getList("+i+")\" >"+i+"</a>";  
        }
    };
    if(data.totalPages>1 && data.nowPage<data.totalPages){
        page=data.nowPage+1;
        html+="<a href=\"javascript:getList("+page+")\" id=\"getList\">下一页</a>";
    }
    html+="</div>";
    $("#test_list").append(html); 
    if(data.data){
      $("#allreport").html("<a class='dowm' href='javascript:allreport();' style='margin-left:-700px;'>批量导出</a>"); 
    }
}

//查看更多
function getList(page){
    p=page;
    ajaxBang();
}
//筛选条件
function select_filter(){
  var name=$("#name").val();
  var test_number=$("#test_number").val();
  var Class=$("#Class").val();
  var year=$("#year").val();
  var class_type=$("#grade").val();
  if(name==""){
    if(year==0){
      alert("请选择时间");
      return ;
    }
    if(test_number==0){
      alert("请选择次数");
      return ;
    } 
    if(Class==0){
      alert("请选择班级");
      return ;
    }
  }
  p=1;
  $.ajax({
    type: "GET",
    url:"{:U('public/TestData/getList')}",
    data:"is_report=0&p="+p+"&name="+name+"&Class="+Class+"&test_number="+test_number+"&year="+year+"&class_type="+class_type,
    dataType:"json",
    success:function(data){
        appendHtml(data);
    }
  });
}

//请求事件
function ajaxBang(){
  var class_type=$("#grade").val();
  $.ajax({
    type: "GET",
    url:"{:U('public/TestData/getList')}",
    data:"is_report=0&p="+p+"&name="+name+"&Class="+Class+"&test_number="+test_number+"&year="+year+"&class_type="+class_type,
    dataType:"json",
    success:function(data){
        appendHtml(data);
    }
  });
}
function allreport(){
  var test_number=$("#test_number").val();
  var Class=$("#Class").val();
  var year=$("#year").val();
  if(Class==0){
    var Class=classId;
  }
  window.location.href="{:U('public/TestData/doexport')}"+"&test_number="+test_number+"&Class="+Class+"&year="+year+"&type=2";
}
function deleteTest(id){
  if(confirm("你确定要删除这条记录？")){
    $.ajax({
      type: "POST",
      url:"{:U('public/TestData/DeleteTest')}",
      data:"id="+id,
      dataType:"text",
      success:function(data){
        if(isNaN(data)){
          alert(data);
        }else{
          window.location.href=window.location.href;
        }
      }
    });
  }
}
function selectGrade(){
  var grade       = $("#grade").val();
  var test_number = $("#test_number").val();
  var year        = $("#year").val();
  if(grade!=""){
    $.ajax({
      type: "GET",
      url:"{:U('public/TestData/getClass')}",
      data:"class_type="+grade+'&is_report=0&test_number='+test_number+'&year='+year,
      dataType:"json",
      success:function(data){
        $("#Class").html("");
        $("#Class").append("<option value=''>--------请选择--------</option>");
        $.each(data,function(i,item){
          $("#Class").append("<option value='"+item.class_id+"'>"+item.class_name+"</option>");
        }); 
      }
    });
  }
}
function selectClass(){
  var Class=$("#Class").val();
  if(Class!=""){
    $.ajax({
      type: "GET",
      url:"{:U('public/TestData/getStu')}",
      data:"Class="+Class,
      dataType:"json",
      success:function(data){
        $("#stu_id").html("");
        $("#stu_id").append("<option value=''>--------请选择--------</option>");
        $.each(data,function(i,item){
          $("#stu_id").append("<option value='"+item.stu_id+"'>"+item.stu_name+"</option>");
        }); 
      }
    });
  }
}
</script>
<include file="../Public/_foot" />